<?php
/**
 * 控制器公共类(基础类)文件
 */
namespace app\controller\v1;

use think\App;
use think\facade\View;
use app\model\Category as CategoryModel;
use app\model\System as SystemModel;

use app\BaseController;

/**
 * 控制器基础类
 *
 * @category index
 * @package  Controller
 * @author   huwhois <huwhois@163.com>
 */
class Base extends BaseController
{ 
    protected $system;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $eng = View::engine();

        $eng->layout('v1/layout');

        $list = CategoryModel::field('id, parent_id, name, url, type')->where('is_nav', 1)->cache(false)->order('sort asc, id asc')->select();

        $categories = list_tree($list, 'id', 'parent_id');
        
        View::assign('categories', $categories);
        
        $this->system = SystemModel::find(1)->toArray();
        
        View::assign('system', $this->system);

        $cid = (int) $this->request->param('cid');
       
        $category_info = CategoryModel::field('id, parent_id, name, url, type')->find($cid);

        View::assign('category_info', $category_info);
    }

    // 404 页面
    public function notFound($msg = '')
    {
        View::engine()->layout(false);

        $filename = $this->app->getRootPath() . "view" . DIRECTORY_SEPARATOR . "404.html";

        return View::fetch($filename, ['msg' => $msg]);
    }
}
